package com.cryptooj.project.judge.codesandbox;

import com.cryptooj.project.judge.codesandbox.model.ExecuteCodeRequest;
import com.cryptooj.project.judge.codesandbox.model.ExecuteCodeResponse;
import lombok.extern.slf4j.Slf4j;

/**
 *  代码沙箱代理
 *  （加一层，实现功能增强）
 *  （这里实际上是在简化代码，避免在多个xxxCodeSandbox中书写重复代码，如log.info()）
 * */
@Slf4j
public class CodeSandboxProxy implements CodeSandbox{

    private final CodeSandbox codeSandbox;

    public CodeSandboxProxy(CodeSandbox codeSandbox) {
        this.codeSandbox = codeSandbox;
    }

    @Override
    public ExecuteCodeResponse executeCode(ExecuteCodeRequest executeCodeRequest) {
        log.info("代码沙箱请求消息为："+executeCodeRequest.toString()); // proxy增强
        ExecuteCodeResponse executeCodeResponse = codeSandbox.executeCode(executeCodeRequest);
        log.info("代码沙箱响应消息为："+executeCodeResponse.toString()); // proxy增强

        return executeCodeResponse;
    }
}
